from lxml import etree


def extract_xml_text(file_path):
    with open(file_path, "r", encoding="utf-8") as f:
        xml = f.read()
    root = etree.fromstring(xml.encode("utf8"))
    # 遍历XML文档树，提取所有的文本内容并且最后用空格连接
    text = " ".join(root.itertext())
    return text


# 主程序入口，进行测试调用
if __name__ == "__main__":
    # 调用函数，读取并打印example.json文件内容
    result = extract_xml_text("example.xml")
    print(result)

# xml => json => proto buffer
